<template>
  <a-layout
    id="components-layout-demo-custom-trigger"
    style="min-height: 100vh"
  >
    <a-layout-sider :trigger="null" collapsible>
      <div class="title">健康医典</div>
      <a-menu
        theme="dark"
        mode="inline"
        :default-selected-keys="['3']"
        :selected-keys="[`${selectedMenu}`]"
        v-for="item in menuList"
        @click="handleClick"
      >
        <a-menu-item :key="item.key">
          <router-link :to="item.path">
            <span :class="item.icon" class="iconfont"></span>
            <span>{{ item.name }}</span>
          </router-link>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <a-dropdown>
          <a class="user ant-dropdown-link">
            <img src="~assets/img/avatar.jpg" alt="" />
          </a>
          <template #overlay>
            <a-menu>
              <a-menu-item
                style="width: 60px; text-align: center"
                @click="loginout()"
              >
                退出
              </a-menu-item>
            </a-menu>
          </template>
        </a-dropdown>
      </a-layout-header>
      <a-layout-content
        :style="{ margin: '24px 16px', padding: '24px', background: '#fff' }"
      >
        <router-view></router-view>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>
<script>
import { h, ref, toRefs, reactive, onMounted, computed, watch } from "vue";
import { onBeforeRouteUpdate, useRoute, useRouter } from "vue-router";

export default {
  setup() {
    const router = useRouter();
    const state = reactive({
      menuList: [
        {
          key: "user",
          name: "用户管理",
          icon: "yonghu",
          path: "/user",
        },
        {
          key: "diseaseType",
          name: "疾病分类管理",
          icon: "dingdandingdanmingxishouzhimingxi",
          path: "/diseaseType",
        },
        {
          key: "disease",
          name: "疾病管理",
          icon: "zhedie",
          path: "/disease",
        },
        {
          key: "artical",
          name: "文章管理",
          icon: "pinglun",
          path: "/artical",
        },
        {
          key: "video",
          name: "视频管理",
          icon: "shuye",
          path: "/video",
        },
        {
          key: "live",
          name: "直播记录",
          icon: "fabusekuai",
          path: "/live",
        },
      ],
      selectedMenu: "user",
    });
    onMounted(() => {
      state.selectedMenu = window.sessionStorage.getItem("path") || "user";
    });
    const handleClick = (e) => {
      state.selectedMenu = e.key;
      window.sessionStorage.setItem("path", e.key);
    };
    const loginout = () => {
      window.sessionStorage.clear()
      router.push({
        path: "/login",
      });
    };
    return {
      ...toRefs(state),
      handleClick,
      loginout,
    };
  },
};
</script>
<style lang="less" scoped>
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px;
}
.title {
  text-align: center;
  color: #fff;
  font-weight: bold;
  line-height: 70px;
  font-size: 22px;
}
.iconfont {
  margin-right: 10px;
}
.user {
  position: absolute;
  right: 30px;
  img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
</style>
